import service from '@/services/login/index'
import store from 'store'
import { TOKEN_LOCA_NAME,USER_INFO_LOCAL_NAME } from '@/utils/index'
export default {
    state:{
        user:{},
        token:null,
        menuList:[]
    },
    effects:{
        *login({payload},{call,put}){
            try {
                const res = yield call(service.LoginController.saveLogin,payload)
                yield put({
                    type:'save',
                    payload:{
                        user: res,
                        token: res.token
                    }
                })
                store.set(TOKEN_LOCA_NAME,res.token)
                store.set(USER_INFO_LOCAL_NAME,res)
                return {userInfo:res}
            } catch (error) {
                return Promise.reject(error)
            }
            
        },
       
    },
    reducers:{
        save(state,{payload}){
            return {
                ...state,
                ...payload,
                
            }
        }
    }
}